package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	
	public class FrameLover extends JFrame
	{
		//members define
		private var panelButtons:JPanel;
		private var btn_lover_flower:JButton;
		private var btn_lover_care:JButton;
		private var btn_lover_kiss:JButton;
		private var btn_lover_ravage:JButton;
		private var btn_lover_pair:JButton;
		private var btn_lover_chat:JButton;
		private var btn_lover_watch:JButton;
		private var btn_lover_home:JButton;
		private var btn_lover_desert:JButton;
		private var btn_lover_battle:JButton;
		private var btn_lover_rest:JButton;
		private var panelImageSelf:JPanel;
		private var labelNameSelf:JLabel;
		private var labelValueSelf:JLabel;
		private var panelImageLover:JPanel;
		private var labelName:JLabelButton;
		private var labelValue:JLabel;
		private var labelInfoLoverMaster:JLabel;
		private var labelLoverMaster:JLabelButton;
		private var scrollpane:JScrollPane;
		private var labelInfos:MultilineLabel;
		private var panel24:JPanel;
		private var btn_battle_setting:JButton;
		private var btn_find_lover:JButton;
		
		
		private var btn_close:JButton;
		public function FrameLover()
		{
			setClosable(false);
			setResizable(false);  
			setBorder(new EmptyBorder());
			btn_close = new JButton();
			//btn_close.setLocation(new IntPoint(453, 8));
			btn_close.setSize(new IntDimension(27, 27));
			btn_close.setPreferredSize(new IntDimension(27, 27));
			this.getTitleBar().setCloseButton(btn_close);
			this.getTitleBar().setMinimizeHeight(32);
			this.setClipMasked(false);
			
			//component creation
			setSize(new IntDimension(510, 357));
			setPreferredSize(new IntDimension(510, 357));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panelButtons = new JPanel();
			panelButtons.setLocation(new IntPoint(421, 14));
			panelButtons.setSize(new IntDimension(56, 264));
			panelButtons.setPreferredSize(new IntDimension(56, 264));
			var layout1:BoxLayout = new BoxLayout();
			layout1.setAxis(AsWingConstants.VERTICAL);
			layout1.setGap(0);
			panelButtons.setLayout(layout1);
			
			btn_lover_flower = new JButton();
			btn_lover_flower.setLocation(new IntPoint(0, 0));
			btn_lover_flower.setSize(new IntDimension(56, 24));
			btn_lover_flower.setPreferredSize(new IntDimension(56, 24));
			btn_lover_flower.setText("label");
			
			btn_lover_care = new JButton();
			btn_lover_care.setLocation(new IntPoint(0, 24));
			btn_lover_care.setSize(new IntDimension(56, 24));
			btn_lover_care.setPreferredSize(new IntDimension(56, 24));
			btn_lover_care.setText("label");
			
			btn_lover_kiss = new JButton();
			btn_lover_kiss.setLocation(new IntPoint(0, 48));
			btn_lover_kiss.setSize(new IntDimension(56, 24));
			btn_lover_kiss.setPreferredSize(new IntDimension(56, 24));
			btn_lover_kiss.setText("label");
			
			btn_lover_ravage = new JButton();
			btn_lover_ravage.setLocation(new IntPoint(0, 72));
			btn_lover_ravage.setText("label");
			
			btn_lover_pair = new JButton();
			btn_lover_pair.setLocation(new IntPoint(0, 96));
			btn_lover_pair.setSize(new IntDimension(56, 24));
			btn_lover_pair.setPreferredSize(new IntDimension(56, 24));
			btn_lover_pair.setText("label");
			
			btn_lover_chat = new JButton();
			btn_lover_chat.setLocation(new IntPoint(0, 120));
			btn_lover_chat.setSize(new IntDimension(56, 24));
			btn_lover_chat.setPreferredSize(new IntDimension(56, 24));
			btn_lover_chat.setText("label");
			
			btn_lover_watch = new JButton();
			btn_lover_watch.setLocation(new IntPoint(71, 220));
			btn_lover_watch.setSize(new IntDimension(56, 24));
			btn_lover_watch.setPreferredSize(new IntDimension(56, 24));
			btn_lover_watch.setText("label");
			
			btn_lover_home = new JButton();
			btn_lover_home.setLocation(new IntPoint(155, 286));
			btn_lover_home.setSize(new IntDimension(56, 24));
			btn_lover_home.setPreferredSize(new IntDimension(56, 24));
			btn_lover_home.setText("label");
			
			btn_lover_desert = new JButton();
			btn_lover_desert.setLocation(new IntPoint(267, 286));
			btn_lover_desert.setSize(new IntDimension(56, 24));
			btn_lover_desert.setPreferredSize(new IntDimension(56, 24));
			btn_lover_desert.setText("label");
			
			btn_lover_battle = new JButton();
			btn_lover_battle.setLocation(new IntPoint(323, 286));
			btn_lover_battle.setSize(new IntDimension(56, 24));
			btn_lover_battle.setPreferredSize(new IntDimension(56, 24));
			btn_lover_battle.setText("label");
			
			btn_lover_rest = new JButton();
			btn_lover_rest.setSize(new IntDimension(56, 24));
			btn_lover_rest.setPreferredSize(new IntDimension(56, 24));
			btn_lover_rest.setText("label");
			
			panelImageSelf = new JPanel();
			panelImageSelf.setLocation(new IntPoint(121, 16));
			panelImageSelf.setSize(new IntDimension(132, 257));
			panelImageSelf.setPreferredSize(new IntDimension(132, 257));
			var layout2:FlowWrapLayout = new FlowWrapLayout();
			layout2.setPreferWidth(200);
			layout2.setAlignment(AsWingConstants.LEFT);
			layout2.setHgap(0);
			layout2.setVgap(0);
			panelImageSelf.setLayout(layout2);
			
			labelNameSelf = new JLabel();
			labelNameSelf.setLocation(new IntPoint(5, 5));
			labelNameSelf.setSize(new IntDimension(26, 17));
			labelNameSelf.setPreferredSize(new IntDimension(132, 20));
			labelNameSelf.setText("label");
			
			labelValueSelf = new JLabel();
			labelValueSelf.setLocation(new IntPoint(0, 20));
			labelValueSelf.setSize(new IntDimension(132, 20));
			labelValueSelf.setPreferredSize(new IntDimension(132, 20));
			labelValueSelf.setText("label");
			
			panelImageLover = new JPanel();
			panelImageLover.setLocation(new IntPoint(262, 16));
			panelImageLover.setSize(new IntDimension(132, 257));
			panelImageLover.setPreferredSize(new IntDimension(132, 257));
			var layout3:FlowWrapLayout = new FlowWrapLayout();
			layout3.setPreferWidth(200);
			layout3.setAlignment(AsWingConstants.LEFT);
			layout3.setHgap(0);
			layout3.setVgap(0);
			panelImageLover.setLayout(layout3);
			
			labelName = new JLabelButton();
			labelName.setSize(new IntDimension(132, 20));
			labelName.setPreferredSize(new IntDimension(132, 20));
			labelName.setText("label");
			
			labelValue = new JLabel();
			labelValue.setLocation(new IntPoint(26, 0));
			labelValue.setSize(new IntDimension(132, 20));
			labelValue.setPreferredSize(new IntDimension(132, 20));
			labelValue.setText("label");
			
			labelInfoLoverMaster = new JLabel();
			labelInfoLoverMaster.setLocation(new IntPoint(10, 290));
			labelInfoLoverMaster.setSize(new IntDimension(80, 20));
			labelInfoLoverMaster.setPreferredSize(new IntDimension(80, 20));
			labelInfoLoverMaster.setText("我的情主:");
			
			labelLoverMaster = new JLabelButton();
			labelLoverMaster.setLocation(new IntPoint(90, 290));
			labelLoverMaster.setSize(new IntDimension(120, 20));
			labelLoverMaster.setPreferredSize(new IntDimension(120, 20));
			labelLoverMaster.setText("label");
			
			scrollpane = new JScrollPane();
			scrollpane.setLocation(new IntPoint(9, 3));
			scrollpane.setSize(new IntDimension(116, 279));
			scrollpane.setPreferredSize(new IntDimension(116, 279));
			
			labelInfos = new MultilineLabel();
			labelInfos.setSize(new IntDimension(116, 274));
			
			panel24 = new JPanel();
			panel24.setLocation(new IntPoint(323, 290));
			panel24.setSize(new IntDimension(154, 23));
			panel24.setPreferredSize(new IntDimension(154, 23));
			var layout4:FlowWrapLayout = new FlowWrapLayout();
			layout4.setPreferWidth(200);
			layout4.setAlignment(AsWingConstants.CENTER);
			layout4.setHgap(10);
			layout4.setVgap(0);
			layout4.setMargin(false);
			panel24.setLayout(layout4);
			
			btn_battle_setting = new JButton();
			btn_battle_setting.setLocation(new IntPoint(41, 0));
			btn_battle_setting.setSize(new IntDimension(72, 23));
			btn_battle_setting.setPreferredSize(new IntDimension(72, 23));
			btn_battle_setting.setToolTipText("自动战斗设置");
			btn_battle_setting.setText("战斗设置");
			
			btn_find_lover = new JButton();
			btn_find_lover.setLocation(new IntPoint(82, 0));
			btn_find_lover.setSize(new IntDimension(72, 23));
			btn_find_lover.setPreferredSize(new IntDimension(72, 23));
			btn_find_lover.setToolTipText("打开好友界面寻找情人");
			btn_find_lover.setText("寻找情人");
			
			//component layoution
			getContentPane().append(panelButtons);
			getContentPane().append(panelImageSelf);
			getContentPane().append(panelImageLover);
			getContentPane().append(labelInfoLoverMaster);
			getContentPane().append(labelLoverMaster);
			getContentPane().append(scrollpane);
			getContentPane().append(panel24);
			
			panelButtons.append(btn_lover_flower);
			panelButtons.append(btn_lover_care);
			panelButtons.append(btn_lover_kiss);
			panelButtons.append(btn_lover_ravage);
			panelButtons.append(btn_lover_pair);
			panelButtons.append(btn_lover_chat);
			panelButtons.append(btn_lover_watch);
			panelButtons.append(btn_lover_home);
			panelButtons.append(btn_lover_desert);
			panelButtons.append(btn_lover_battle);
			panelButtons.append(btn_lover_rest);
			
			panelImageSelf.append(labelNameSelf);
			panelImageSelf.append(labelValueSelf);
			
			panelImageLover.append(labelName);
			panelImageLover.append(labelValue);
			
			scrollpane.append(labelInfos);
			
			panel24.append(btn_battle_setting);
			panel24.append(btn_find_lover);
			
			
			//onUpdateData();

			panelImageSelf.setEnabled(false);
			panelImageLover.setEnabled(false);
			panelImageSelf.setClipMasked(false);
			panelImageLover.setClipMasked(false);
			this.setClipMasked(false);
			this.getContentPane().setClipMasked(false);
			setImages();
		}
		
		private var _loaderLover:CharImageLoader = null;
		public function updateLoverImage():void
		{
			if(_loaderLover == null)
				_loaderLover = new CharImageLoader;
			
			var imgSelf:Container = panelImageLover;
			if(_mcLoverImage != null && imgSelf.contains(_mcLoverImage))
			{
				imgSelf.removeChild(_mcLoverImage)
				//_mcLoverImage = null;
			}
			
			if(CharInfo.objLover.loverId == 0)
				return;
			
			if(CharInfo.objLover.m_nCharId == 0)
				return;
			if(_mcLoverImage != null && !imgSelf.contains(_mcLoverImage))
				panelImageLover.addChildAt(_mcLoverImage,0);
			_loaderLover.loadChar(CharInfo.objLover.m_nRace,CharInfo.objLover.m_nGender,CharInfo.objLover.m_arEquips,onLoverLoaded);
		}
		private var _mcLoverImage:MovieClip = null;
		private function onLoverLoaded():void
		{
			
			var imgSelf:Container = panelImageLover;
			if(_mcLoverImage != null && imgSelf.contains(_mcLoverImage))
			{
				imgSelf.removeChild(_mcLoverImage)
				_mcLoverImage = null;
			}
			_mcLoverImage = _loaderLover.getImage("mc_object_stand",true);
			var mc:MovieClip = _mcLoverImage;
			if(mc == null)
				return;

			mc.enabled = false;
			mc.scaleX = 1.0;
			mc.scaleY = 1.0;
			mc.x = (imgSelf.width - mc.width)/2;
			mc.y = (imgSelf.height - mc.height);
			imgSelf.setBackgroundDecorator(null);
			imgSelf.addChildAt(mc,0);
			mc.scaleX = -1.0;
			mc.x = mc.x*mc.scaleX +imgSelf.width;
			
		}
		
		private var _mcCharImage:MovieClip = null;
		private function onCharLoaded():void
		{
			var imgSelf:Container = panelImageSelf;
			if(_mcCharImage != null && imgSelf.contains(_mcCharImage))
			{
				imgSelf.removeChild(_mcCharImage)
				_mcCharImage = null;
			}
			_mcCharImage = _loaderChar.getImage("mc_object_stand",true);
			var mc:MovieClip = _mcCharImage;
			if(mc == null)
				return;
			//mc.gotoAndStop(1);
			//mc.play();
			mc.enabled = false;
			mc.scaleX = 1.0;
			mc.scaleY = 1.0;
			mc.x = (imgSelf.width - mc.width)/2;
			mc.y = (imgSelf.height - mc.height);
			if(CharInfo.objLover.m_nGender == 0)
				mc.y += Client._headOffsetYBoy*mc.scaleY;
			else
				mc.y += Client._headOffsetYGirl*mc.scaleY;
			imgSelf.setBackgroundDecorator(null);
			imgSelf.addChildAt(_mcCharImage,0);
			panelImageSelf.paintImmediately();
			updateLoverImage();
			
		}
		
		private var _loaderChar:CharImageLoader = null;
		public function updateCharImage():void
		{
			if(_loaderChar == null)
				_loaderChar = new CharImageLoader;
			var arCharEquips:Array = new Array();
			//if(CharInfo.m_nImageId != 0)
			//{
			//	arCharEquips.push(Engine.assetMapMonsterPath + "npc_"+ CharInfo.m_nImageId + '.swf');
			//}
			//else
			//{
				for each(var item:Object in CharInfo.m_arItemPage[0])
				{
					if(item.csv_id != 0)
					{
						var objItemCSV:Object = Client.getInstance().GetItemCSV(item.csv_id);
						arCharEquips.push(objItemCSV.equip_image_id);
					}
					else
					{
						arCharEquips.push(0);
					}
				}
			//}
			_loaderChar.loadChar(CharInfo.m_nRace,CharInfo.m_nGender,arCharEquips,onCharLoaded);
		}
		public function setImages():void
		{
			var img_char_background:DisplayObject = Client.getUIElement("img_lover_bg") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_char_background));
			setSizeWH(img_char_background.width,img_char_background.height);
			setLocationXY((Engine.W - img_char_background.width) / 2,(Engine.H - img_char_background.height)/2);
			
			btn_lover_watch.wrapSimpleButton(Client.getUIElement("btn_lover_watch") as SimpleButton);
			btn_lover_watch.setText("");
			btn_lover_chat.wrapSimpleButton(Client.getUIElement("btn_lover_chat") as SimpleButton);
			btn_lover_chat.setText("");
			btn_lover_ravage.wrapSimpleButton(Client.getUIElement("btn_lover_ravage") as SimpleButton);
			btn_lover_ravage.setText("");
			btn_lover_home.wrapSimpleButton(Client.getUIElement("btn_lover_home") as SimpleButton);
			btn_lover_home.setText("");
			btn_lover_pair.wrapSimpleButton(Client.getUIElement("btn_lover_pair") as SimpleButton);
			btn_lover_pair.setText("");
			btn_lover_desert.wrapSimpleButton(Client.getUIElement("btn_lover_desert") as SimpleButton);
			btn_lover_desert.setText("");
			btn_lover_battle.wrapSimpleButton(Client.getUIElement("btn_lover_battle") as SimpleButton);
			btn_lover_battle.setText("");
			btn_lover_kiss.wrapSimpleButton(Client.getUIElement("btn_lover_kiss") as SimpleButton);
			btn_lover_kiss.setText("");
			btn_lover_flower.wrapSimpleButton(Client.getUIElement("btn_lover_flower") as SimpleButton);
			btn_lover_flower.setText("");
			btn_lover_care.wrapSimpleButton(Client.getUIElement("btn_lover_care") as SimpleButton);
			btn_lover_care.setText("");
			btn_lover_rest.wrapSimpleButton(Client.getUIElement("btn_lover_rest") as SimpleButton);
			btn_lover_rest.setText("");
			
			btn_battle_setting.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_battle_setting.setText("战斗设置");
			btn_find_lover.wrapSimpleButton(Client.getUIElement("btn_4") as SimpleButton);
			btn_find_lover.setText("寻找情人");
			
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			btn_close.setText("");
			btn_lover_chat.addActionListener(onBtnChat);
			
			panelImageSelf.setClipMasked(false);
			panelImageLover.setClipMasked(false);
			updateCharImage();
			//updateLoverImage();
			btn_lover_watch.addActionListener(onBtnWatch);
			btn_lover_desert.addActionListener(onBtnDesert);
			btn_lover_battle.addActionListener(onBtnJoinBattle);
			btn_lover_rest.addActionListener(onBtnRest)
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 13, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelName.setForeground(ASColor.WHITE);
			labelName.setFont(new ASFont("宋体", 13, false, false, true, false));
			labelName.setTextFilters(new Array(filter));
			
			labelValue.setForeground(ASColor.YELLOW);
			labelValue.setFont(font);
			labelValue.setTextFilters(new Array(filter));
			
			labelNameSelf.setForeground(ASColor.WHITE);
			labelNameSelf.setFont(font);
			labelNameSelf.setTextFilters(new Array(filter));
			
			labelValueSelf.setForeground(ASColor.YELLOW);
			labelValueSelf.setFont(font);
			labelValueSelf.setTextFilters(new Array(filter));
			
			font = new ASFont("宋体", 13, false, false, false, false);
			
			labelInfoLoverMaster.setForeground(ASColor.WHITE);
			labelInfoLoverMaster.setFont(font);
			labelInfoLoverMaster.setTextFilters(new Array(filter));
			
			labelLoverMaster.setForeground(ASColor.GREEN);
			labelLoverMaster.setMideground(ASColor.RED);
			labelLoverMaster.setFont(new ASFont("宋体", 13, false, false, true, false));
			labelLoverMaster.setBackground(ASColor.GRAY);
			
			labelLoverMaster.addActionListener(onBtnLoverMaster);
			
			labelLoverMaster.filters = new Array(filter);
			labelInfos.setForeground(new ASColor(0x85edb8));
			labelInfos.filters = new Array(filter);
			
			scrollpane.getVerticalScrollBar().setVisible(true);
			scrollpane.setVerticalScrollBarPolicy(JScrollPane.SCROLLBAR_ALWAYS);
			scrollpane.setHorizontalScrollBarPolicy(JScrollPane.SCROLLBAR_NEVER);
			scrollpane.setLayout(new ScrollPaneLayout(ScrollPaneLayout.TOP_LEFT));
			
			scrollpane.getVerticalScrollBar().setUIElement(true);
			scrollpane.getVerticalScrollBar().setUI(new MyScrollBarUI);
			labelInfos.addEventListener(TextEvent.LINK, linkHandler);
			labelName.addActionListener(onBtnName);
			
			font = new ASFont("宋体", 13, false, false, false, false);
			
			btn_battle_setting.setForeground(ASColor.WHITE);
			btn_battle_setting.setTextFilters(new Array(filter));
			btn_battle_setting.setFont(font);
			
			btn_find_lover.setForeground(ASColor.WHITE);
			btn_find_lover.setTextFilters(new Array(filter));
			btn_find_lover.setFont(font);
			btn_battle_setting.addActionListener(onBtnBattleSetting);
			btn_find_lover.addActionListener(onBtnFindLover);
		}
		private function onBtnBattleSetting(e:Event):void
		{
			if(FrameFriend.isShowing())
				FrameFriend.hide();
			FrameBattleSetting.show(_frame,FrameBattleSetting.BATTLE_SETTING_TYPE_LOVER);
		}
		private function onBtnFindLover(e:Event):void
		{
			if(FrameFriend.isShowing())
				FrameFriend.hide();
			if(FrameBattleSetting.isShowing())
				FrameBattleSetting.hide();
			FrameFriend.show(_frame);
		}
		private function onBtnName(e:Event):void
		{
			if(CharInfo.objLover.m_nCharId == 0)
				return;

			var obj:Object = new Object;
			obj.m_nCharId = int(CharInfo.objLover.m_nCharId);
			obj.m_szCharName = CharInfo.objLover.m_szCharName;
			obj.m_nLevel = int(CharInfo.objLover.m_nLevel);
			obj.m_nRace = int(CharInfo.objLover.m_nRace);
			obj.m_nGender = int(CharInfo.objLover.m_nGender);
			
			var point:IntPoint = AsWingUtils.getStageMousePosition();
			FrameClickChar._objDest = obj;
			FrameClickChar._destCharId = int(obj.m_nCharId);
			FrameClickChar.show(_frame,point.x-_frame.x,point.y-_frame.y);
		}
		
		private function linkHandler(linkEvent:TextEvent):void 
		{
			//trace("linkEvent.target:"+linkEvent.target+",linkEvent.currentTarget:"+linkEvent.currentTarget);
			var dtemp:Array = (linkEvent.text as String).split(',');
			if(dtemp.length != 5)
			{
				return;
			}
			
			var obj:Object = new Object;
			obj.m_nCharId = int(dtemp[0]);
			obj.m_szCharName = dtemp[1];
			obj.m_nLevel = int(dtemp[2]);
			obj.m_nRace = int(dtemp[3]);
			obj.m_nGender = int(dtemp[4]);
			
			//trace(linkEvent.text);
			//FrameInfo.showMessageDialog("","这是一个物品"+linkEvent.text);
			var point:IntPoint = AsWingUtils.getStageMousePosition();
			FrameClickChar._objDest = obj;
			FrameClickChar._destCharId = int(obj.m_nCharId);
			FrameClickChar.show(_frame,point.x-_frame.x,point.y-_frame.y);
			//FrameClickChar.show(0,0);
			//trace("point.x:"+point.x+" point.y:"+point.y);
		}
		
		private function onBtnChat(e:Event):void
		{
			if(CharInfo.objLover.m_nCharId != 0)
			{
				var obj:Object = new Object;
				obj.m_nCharId = int(CharInfo.objLover.m_nCharId);
				obj.m_szCharName = CharInfo.objLover.m_szCharName;
				obj.m_nLevel = int(CharInfo.objLover.m_nLevel);
				obj.m_nRace = int(CharInfo.objLover.m_nRace);
				obj.m_nGender = int(CharInfo.objLover.m_nGender);
				
				FrameFriendChat.show(obj);
			}
		}
		private function onBtnLoverMaster(e:Event):void
		{
			if(int(CharInfo.objLover.m_nLoverMasterCharId) == 0)
			{
				PanelMain.showInfoTimeLimit("你还没有干爹!");
				return;
			}
			var obj:Object = new Object;
			obj.m_nCharId = int(CharInfo.objLover.m_nLoverMasterCharId);
			obj.m_szCharName = CharInfo.objLover.m_szLoverMasterCharName;
			obj.m_nLevel = int(CharInfo.objLover.m_nLoverMasterLevel);
			obj.m_nRace = int(CharInfo.objLover.m_nLoverMasterRace);
			obj.m_nGender = int(CharInfo.objLover.m_nLoverMasterGender);
			
			var point:IntPoint = AsWingUtils.getStageMousePosition();
			FrameClickChar._objDest = obj;
			FrameClickChar._destCharId = int(obj.m_nCharId);
			FrameClickChar.show(_frame,point.x-_frame.x,point.y-_frame.y);
		}
		private function onBtnWatch(e:Event):void
		{
			Client.getInstance().sendPacketLogic(605,[int(CharInfo.objLover.m_nCharId)]);
		}
		private function onBtnDesert(e:Event):void
		{
			if(CharInfo.objLover == null)
				return;
			if(CharInfo.objLover.m_szCharName == null)
				return;
			if(CharInfo.objLover.m_szCharName.length == 0)
				return;
			var pane:FrameInfo = FrameInfo.showMessageDialog("","是否将情人 "+CharInfo.objLover.m_szCharName+" 抛弃?",handleOptionDesertLover,null,true,null,JOptionPane.YES|JOptionPane.NO);
		}
		private function handleOptionDesertLover(button:uint):void
		{
			if(button == JOptionPane.YES)
			{
				Client.getInstance().sendPacketLogic(1203,[CharInfo.charId]);
			}
		}
		private function onBtnJoinBattle(e:Event):void
		{
			Client.getInstance().sendPacketLogic(1202,[int(1),CharInfo.charId]);
		}
		private function onBtnRest(e:Event):void
		{
			Client.getInstance().sendPacketLogic(1202,[int(0),CharInfo.charId]);
		}
		private var textTrendsSelf:String = '';
		public function update():void
		{
			updateCharImage();
			updateLoverImage();
			labelNameSelf.setText(CharInfo.charName+' Lv.'+CharInfo.m_nLevel);
			labelNameSelf.setForeground(new ASColor(CharInfo.m_nGender == 0 ? Engine.colorBoy:Engine.colorGirl));
			labelValueSelf.setText('身价: '+CharInfo.value.toString());
			labelName.setText('');
			labelValue.setText('');
			
			if(CharInfo.objLover.loverId  != 0)
			{
				labelName.setText(CharInfo.objLover.m_szCharName+' Lv.'+CharInfo.objLover.m_nLevel);
				labelName.setForeground(new ASColor(CharInfo.objLover.m_nGender == 0 ? Engine.colorBoy:Engine.colorGirl));
				labelValue.setText('身价: '+CharInfo.objLover.m_nValue);
			}
			//labelValueSelf.setText(CharInfo.value.toString());	
			if(CharInfo.objLover.m_nLoverMasterCharId == 0)
				labelLoverMaster.setText("");
			else
			{
				labelLoverMaster.setForeground(new ASColor(CharInfo.objLover.m_nLoverMasterGender == 0 ? Engine.colorBoy:Engine.colorGirl));
				labelLoverMaster.setText(CharInfo.objLover.m_szLoverMasterCharName+' Lv.'+CharInfo.objLover.m_nLoverMasterLevel);
			}
			
			textTrendsSelf = "";
			labelInfos.setHtmlText(textTrendsSelf);
			for each(var item:Object in CharInfo.m_mapListTrends[Const.TREND_TYPE_LOVER])
			{
				textTrendsSelf += item.m_szMessage +"<br><br>";
			}
			labelInfos.setHtmlText(textTrendsSelf);
			labelInfos.scrollToBottomLeft();
			

			btn_battle_setting.setEnabled(hasLover());
			btn_lover_flower.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_care.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_kiss.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_ravage.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_pair.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_chat.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_watch.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_home.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_desert.setEnabled(CharInfo.objLover.loverId != 0);
			btn_lover_battle.setEnabled(CharInfo.objLover.loverId  != 0 && CharInfo.m_nBattlePartnerType != PanelMain.PARTNER_TYPE_LOVER);
			btn_lover_rest.setEnabled(CharInfo.objLover.loverId  != 0 && CharInfo.m_nBattlePartnerType == PanelMain.PARTNER_TYPE_LOVER);
		}
		public static function hasLover():Boolean
		{
			return (CharInfo.objLover.m_nCharId != 0);
		}
		public static function phLover_1200(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phLover_1200", msg);
			var nIndex:uint = 0;
			var obj:Object = CharInfo.objLover;
			CharInfo.objLover.m_nLoverMasterCharId = msg[nIndex++];
			CharInfo.objLover.m_szLoverMasterCharName = msg[nIndex++];
			CharInfo.objLover.m_nLoverMasterRace = msg[nIndex++];
			CharInfo.objLover.m_nLoverMasterGender = msg[nIndex++];
			CharInfo.objLover.m_nLoverMasterLevel = msg[nIndex++];
			CharInfo.objLover.m_nLoverMasterValue = msg[nIndex++];
			
			CharInfo.objLover.loverId = msg[nIndex++];
			CharInfo.objLover.m_nInnerId = CharInfo.objLover.loverId;
			CharInfo.objLover.m_nCharId = msg[nIndex++];
			if(CharInfo.objLover.m_nCharId != 0)
			{
				CharInfo.objLover.m_szCharName = msg[nIndex++];
				CharInfo.objLover.m_nRace = msg[nIndex++];
				CharInfo.objLover.m_nGender = msg[nIndex++];
				CharInfo.objLover.m_nLevel = msg[nIndex++];
				CharInfo.objLover.m_nValue = msg[nIndex++];
				CharInfo.objLover.m_nRelation = msg[nIndex++];
				CharInfo.objLover.m_nLove = msg[nIndex++];
	
				CharInfo.objLover.m_nDesertTimes = msg[nIndex++];
				
				CharInfo.objLover.m_nCaughtTimes = msg[nIndex++];
				CharInfo.objLover.m_nHPMax = msg[nIndex++];
				
				CharInfo.objLover.m_nAP = msg[nIndex++];
				CharInfo.objLover.m_nSP = msg[nIndex++];
				CharInfo.objLover.m_nResistHY = msg[nIndex++];
				CharInfo.objLover.m_nResistZS = msg[nIndex++];
				CharInfo.objLover.m_nResistJD = msg[nIndex++];
				CharInfo.objLover.m_arSkills = new Array();
				var nSkills:uint = msg[nIndex++];
				for(var j:int = 0; j < nSkills; j++)
				{
					var objSkill:Object = new Object();
					objSkill.csv_id = msg[nIndex++];
					objSkill.m_nLevel = msg[nIndex++];
					CharInfo.objLover.m_arSkills[j] = objSkill;
				}
				
				obj.m_nBattleMode = msg[nIndex++];
				obj.m_arAutoBattleSkills = [];
				for(var k:int = 0; k < 6; k++)
					obj.m_arAutoBattleSkills[k] = msg[nIndex++];
				obj.m_arAutoBattleSkillsSoul = [];
				for(k = 0; k < 6; k++)
					obj.m_arAutoBattleSkillsSoul[k] = msg[nIndex++];
				
				if(CharInfo.objLover.m_arDefaultSkills == null)
					CharInfo.objLover.m_arDefaultSkills = new Array();
				
				for(var i:int = 0; i < Const.DEFAULT_SKILL_SIZE; i++)
					CharInfo.objLover.m_arDefaultSkills[i] = msg[nIndex++];
				
				CharInfo.objLover.m_arEquips = new Array();
				var nEquips:uint = msg[nIndex++];
				for(j = 0; j < nEquips; j++)
				{
					CharInfo.objLover.m_arEquips[j] =  msg[nIndex++];
				}
			}

			if(_frame == null)
			{
				_frame = new FrameLover();
				PanelMainHelp.getInstance().addChild(_frame);
				FrameLover.hide();
			}
			FrameLover._frame.update();
			PanelMainHelp.getInstance().onPartnerInfoUpdate();
			if(FrameBattleSetting.isShowing())
				FrameBattleSetting._frame.update();
		}
		
		public static var _frame:FrameLover = null;
		public static function show():void
		{
			if(isShowing())
			{
				hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameLover();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			_frame.update();
			PanelMainHelp.getInstance().bringToTop(_frame);
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		
		public static function showTokenOfLove(obj:Object):void
		{
			FrameTokenOfLove.show(obj);
		}
	}
}

import com.*;
import com.Engine.*;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;

class FrameTokenOfLove extends JFrame
{
	//members define
	private var txtInfo:MultilineLabel;
	private var labelName:JLabelButton;
	private var labelValue:JLabel;
	private var panelImage:JPanel;
	private var txtPrice:JTextField;
	private var btn_lover_token_of_love:JButton;
	
	private var btn_close:JButton;
	public function FrameTokenOfLove()
	{
		setClosable(false);
		setResizable(false);  
		setBorder(new EmptyBorder());
		btn_close = new JButton();
		//btn_close.setLocation(new IntPoint(453, 8));
		btn_close.setSize(new IntDimension(27, 27));
		btn_close.setPreferredSize(new IntDimension(27, 27));
		this.getTitleBar().setCloseButton(btn_close);
		this.getTitleBar().setMinimizeHeight(32);
		this.setClipMasked(false);
		
		//component creation
		setSize(new IntDimension(326, 256));
		setPreferredSize(new IntDimension(326, 256));
		var layout0:EmptyLayout = new EmptyLayout();
		getContentPane().setLayout(layout0);
		
		txtInfo = new MultilineLabel();
		txtInfo.setLocation(new IntPoint(20, 11));
		txtInfo.setSize(new IntDimension(131, 189));
		txtInfo.setPreferredSize(new IntDimension(131, 189));
		
		labelName = new JLabelButton();
		labelName.setLocation(new IntPoint(170, 9));
		labelName.setSize(new IntDimension(141, 23));
		labelName.setPreferredSize(new IntDimension(141, 23));
		labelName.setText("label");
		
		labelValue = new JLabel();
		labelValue.setLocation(new IntPoint(170, 35));
		labelValue.setSize(new IntDimension(141, 22));
		labelValue.setPreferredSize(new IntDimension(141, 22));
		labelValue.setText("label");
		
		panelImage = new JPanel();
		panelImage.setLocation(new IntPoint(204, 64));
		panelImage.setSize(new IntDimension(70, 70));
		panelImage.setPreferredSize(new IntDimension(70, 70));
		
		txtPrice = new JTextField();
		txtPrice.setLocation(new IntPoint(202, 162));
		txtPrice.setSize(new IntDimension(75, 23));
		txtPrice.setPreferredSize(new IntDimension(75, 23));
		
		btn_lover_token_of_love = new JButton();
		btn_lover_token_of_love.setLocation(new IntPoint(212, 185));
		btn_lover_token_of_love.setSize(new IntDimension(55, 23));
		btn_lover_token_of_love.setPreferredSize(new IntDimension(55, 23));
		btn_lover_token_of_love.setText("label");
		
		//component layoution
		getContentPane().append(txtInfo);
		getContentPane().append(labelName);
		getContentPane().append(labelValue);
		getContentPane().append(panelImage);
		getContentPane().append(txtPrice);
		getContentPane().append(btn_lover_token_of_love);
		
		//onUpdateData();
		
		panelImage.setEnabled(false);
		this.setClipMasked(false);
		this.getContentPane().setClipMasked(false);
		setImages();
	}
	
	public function setImages():void
	{
		var img_char_background:DisplayObject = Client.getUIElement("img_lover_token_of_love_bg") as DisplayObject
		setBackgroundDecorator(new AssetBackground(img_char_background));
		setSizeWH(img_char_background.width,img_char_background.height);
		setPreferredSize(new IntDimension(img_char_background.width, img_char_background.height));
		setLocationXY((Engine.W - img_char_background.width) / 2,(Engine.H - img_char_background.height)/2);
		
		btn_lover_token_of_love.wrapSimpleButton(Client.getUIElement("btn_lover_token_of_love") as SimpleButton);
		btn_lover_token_of_love.setText("");
		
		btn_lover_token_of_love.addActionListener(onBtnTaokenOfLove);
		
		panelImage.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_head") as DisplayObject));
		
		btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
		btn_close.setText("");

		
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 13, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 5);
		
		txtPrice.setForeground(ASColor.WHITE);
		txtPrice.setFont(font);
		txtPrice.filters = new Array(filter);
		txtPrice.setBackgroundDecorator(null);
		
		txtInfo.setForeground(ASColor.WHITE);
		txtInfo.setFont(font);
		txtInfo.filters = new Array(filter);
		txtInfo.setBackgroundDecorator(null);
		
		labelName.setForeground(ASColor.WHITE);
		labelName.setFont(new ASFont("宋体", 13, false, false, true, false));
		labelName.setTextFilters(new Array(filter));
		
		labelValue.setForeground(ASColor.YELLOW);
		labelValue.setFont(font);
		labelValue.setTextFilters(new Array(filter));
		
		labelName.addActionListener(onBtnName);
		
		var str:String = '';
		str += "1. 可以用高于玩家身价的铜币,使任何玩家身价提升,并且变为自己的情人.<br><br>";
		str += "2. 自己的情人被人抢走后所花铜币不再退回.<br><br>";
		str += "3. 玩家身价越高,对自身属性加成越高,最高10%.<br><br>";
		txtInfo.setHtmlText(str);
	}
	private function onBtnTaokenOfLove(e:Event):void
	{
		if(txtPrice.getText().length <= 0 || int(txtPrice.getText()) == 0)
		{
			FrameInfo.showMessageDialog("","请输入出价!",null,null,true,null);
			return;
		}
		Client.getInstance().sendPacketLogic(1200,[_item.m_nCharId,int(txtPrice.getText())]);
		FrameTokenOfLove.hide();
	}
	private function onBtnName(e:Event):void
	{
		var point:IntPoint = AsWingUtils.getStageMousePosition();
		FrameClickChar._objDest = _item;
		FrameClickChar._destCharId = int(_item.m_nCharId);
		FrameClickChar.show(_frame,point.x-_frame.x,point.y-_frame.y);
	}
	private var _item:Object;
	public function update(obj:Object):void
	{
		_item = obj;
		if(_item == null)
			return;
		
		labelName.setText('');
		labelValue.setText('');
		labelName.setForeground(new ASColor(_item.m_nGender == 0 ? Engine.colorBoy : Engine.colorGirl));
		labelName.setText(_item.m_szCharName+' Lv.'+_item.m_nLevel);
		labelValue.setText('身价:'+_item.value);
	}
	
	
	public static var _frame:FrameTokenOfLove = null;
	public static function show(obj:Object):void
	{
		if(isShowing())
		{
			hide();
			return;
		}
		if(_frame == null)
		{
			_frame = new FrameTokenOfLove();
			PanelMainHelp.getInstance().addChild(_frame);
		}
		_frame.show();
		_frame.update(obj);
		PanelMainHelp.getInstance().bringToTop(_frame);
	}
	public static function hide():void
	{
		if(isShowing())_frame.hide();
	}
	public static function isShowing():Boolean
	{
		return(_frame != null&& _frame.isShowing());
	}
}